/*
 * st7735_spi_stm32.h
 *
 *  Created on: Dec 14, 2012
 *      Author: Andrey Belomutskiy
 */

/*
 *
 * based on http://www.micromouseonline.com/2009/05/26/nokia-3410-lcd-on-the-stm32/
 *
 * PA4 		SPI1_NSS 		Display Select	GPIO_Pin_CS		CS		Red
 * PA5 		SPI1_SCK 		Serial Clock					SCL		Brown
 * PA6 		SPI1_MISO 		Data/Command	GPIO_Pin_DC		RS/DC	White
 * PA7 		SPI1_MOSI 		Serial Data						SDA		Black
 * PA3 		none	 		Display Reset					RES		Grey
 *
 */

#ifndef ST7735_SPI_STM32_H_
#define ST7735_SPI_STM32_H_

#include <stm32f4xx_gpio.h>

#define SPILCD SPI1


#ifndef PAL_PORT_BIT
#define PAL_PORT_BIT(n) ((1 << (n)))
#endif

#define TRUE 1
#define FALSE 0

#define GPIO_LCD	GPIOA

#define GPIO_LCD_DC GPIOA
#define GPIO_LCD_CS GPIOA
#define GPIO_LCD_RST GPIOA

/**
 * the Slave Select pin, SPI1_NSS, will be set in software and so can be left as a GPIO
 */
#define GPIO_Pin_CS 4

#define GPIO_Pin_SCK 5

/**
 * display is a write-only device so there is no use for the MISO pin and it can be used as a GPIO to drive the Data/Command select pin of the display
 */
#define GPIO_Pin_DC 6

#define GPIO_Pin_MOSI 7

#define GPIO_Pin_RST 3

#define SPI_LCD_CS_LOW()        GPIO_ResetBits(GPIO_LCD_CS, PAL_PORT_BIT(GPIO_Pin_CS))
#define SPI_LCD_CS_HIGH()       GPIO_SetBits(GPIO_LCD_CS, PAL_PORT_BIT(GPIO_Pin_CS))

#define SPI_LCD_DC_LOW()        GPIO_ResetBits(GPIO_LCD_DC, PAL_PORT_BIT(GPIO_Pin_DC))
#define SPI_LCD_DC_HIGH()       GPIO_SetBits(GPIO_LCD_DC, PAL_PORT_BIT(GPIO_Pin_DC))

#define SPI_LCD_RST_LOW()       GPIO_ResetBits(GPIO_LCD_RST, PAL_PORT_BIT(GPIO_Pin_RST))
#define SPI_LCD_RST_HIGH()      GPIO_SetBits(GPIO_LCD_RST, PAL_PORT_BIT(GPIO_Pin_RST))

void initSpiForLcd();
void spiLcdCmd(int command);
void spiLcdData(int data);

#endif /* ST7735_SPI_STM32_H_ */
